#include "function.h"
#include "log.h"
SONG songs[] = {
    {"Hitoshizuku","MyGo!!!!!"},
    {"Crucifix X","Ave Mujica"},
    {"KiLLKiSS","Ave Mujica"},
    {"Ave Mujica","Ave Mujica"}
};

int song_count = 4;//设置歌曲数量
PlayState play_state = STOPPED;//设置初始为停止状态
int current = 0;//当前播放索引


//显示当前播放状态
void player_show_status()
{
    printf("当前状态:\n");
    switch(play_state)
    {
        case PLAYING:
        printf("正在播放|%s-%s\n",
            songs[current].song_name,songs[current].singer);
            break;

        case PAUSED:
        printf("已暂停|%s-%s\n",
            songs[current].song_name,songs[current].singer);
            break;

        case STOPPED:
        printf("已停止\n");
        break;
    }
    printf("\n");
}

//音乐播放器开始或者回复播放
void player_play()
{
    if(play_state != PLAYING)
    {
        play_state = PLAYING;
        printf("音乐开始播放：%s-%s\n",
            songs[current].song_name,songs[current].singer);
        log_media("播放", songs[current].song_name, songs[current].singer);
        player_show_status();
    }
}

//音乐播放器暂停
void player_pause()
{
    if(play_state != PAUSED)
    {
        play_state = PAUSED;
        printf("继续播放");
        log_media("暂停", songs[current].song_name, songs[current].singer);
        player_show_status();
    }
}

//音乐播放器停止结束播放
void player_stop()
{
    if(play_state != STOPPED)
    {
        play_state = STOPPED;
        printf("播放结束");
        log_media("停止", songs[current].song_name, songs[current].singer);
        player_show_status();
    }
}

//切歌，切到下一首
void player_next()
{
    if(current<song_count-1)
    {
        current++;
        play_state = PLAYING;
        printf("下一首%s-%s\n",
        songs[current].song_name,songs[current].singer);
        log_media("切歌", songs[current].song_name, songs[current].singer);
        player_show_status();
    }
    else
    {
        printf("已是最后一首");
    }
}

//切歌，切到上一首
void player_prev()
{
    if(current>0)
    {
        current--;
        play_state = PLAYING;
        printf("上一首%s-%s\n",
        songs[current].song_name,songs[current].singer);
        log_media("切歌", songs[current].song_name, songs[current].singer);
        player_show_status();
    }
    else
    {
        printf("已是第一首");
    }
}

//模拟更新车辆状态
void update(VehicleStatus*v)
{
    v->speed = rand() % 160;//0-159km/h
    v->fuel = 20 + rand() % 81;//20-100%
    v->temp = 70 + rand() % 51;//70-120°C
    log_vehicle(v->speed,v->fuel,v->temp);
}

//显示车辆状态
void display(VehicleStatus*v)
{
    printf("Speed:%3d km/h| Fuel:%3d%%| Temp:%3d°C\n",
    v->speed,v->fuel,v->temp);
}

